package com.go.where.manager.action.go;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.go.where.manager.action.SuperAction;
import com.go.where.manager.common.Constants;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.pojo.FamilySubjectInfo;
import com.go.where.manager.service.FamilySubjectService;

public class FamilySubjectAction extends SuperAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4383195694100314090L;
	private static final Logger log = Logger
			.getLogger(FamilySubjectAction.class);

	public Pagination<?> page;

	@Resource(name = "familySubjectService")
	private FamilySubjectService familySubjectService;

	private FamilySubjectInfo familySubjectInfo;
	private FamilySubjectInfo familySubjectInfoQuery;

	private String subjectId;

	/**
	 * 查询列表
	 * 
	 * @return
	 */
	public String list() {
		if (familySubjectInfoQuery == null) {
			familySubjectInfoQuery = new FamilySubjectInfo();
			familySubjectInfoQuery.setPageSize(Constants.INIT_PAGESIZE);
			familySubjectInfoQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
		}
		try {
			familySubjectInfoQuery.setIsDelete(Constants.NOT_DELETED);
			page = familySubjectService.queryPage(familySubjectInfoQuery);
		} catch (Exception e) {
			addActionError(e.getMessage());
			log.error("查询信息异常", e);
		}
		return LIST;
	}

	public String toEdit() {
		familySubjectInfo = familySubjectService.queryByPrimartKey(subjectId);
		return INPUT;
	}

	public String add() {
		return INPUT;
	}

	/**
	 * 保存
	 * 
	 * @return
	 */
	public String save() {
		try {
			if (StringUtils.isBlank(familySubjectInfo.getIsHot())) {
				familySubjectInfo.setIsHot("0");
			}
			familySubjectService.save(familySubjectInfo, getCurrentOperator());
			redirectionUrl = "family_subject!list.htm";
			return SUCCESS;
		} catch (Exception e) {
			log.error("保存信息异常", e);
			addActionError("保存信息异常！" + e);
			return this.add();
		}
	}

	/**
	 * 编辑
	 * 
	 * @return
	 */
	public String edit() {
		try {
			if (StringUtils.isBlank(familySubjectInfo.getIsHot())) {
				familySubjectInfo.setIsHot("0");
			}
			familySubjectService
					.update(familySubjectInfo, getCurrentOperator());
			redirectionUrl = "family_subject!list.htm";
			return SUCCESS;
		} catch (Exception e) {
			log.error("修改信息异常", e);
			addActionError("修改信息异常！" + e);
			subjectId = familySubjectInfo.getSubjectId();
			return this.toEdit();
		}
	}

	/**
	 * 详情
	 * 
	 * @return
	 */
	public String detail() {
		familySubjectInfo = familySubjectService.queryByPrimartKey(subjectId);
		return "detail";
	}

	/**
	 * 假删除
	 * 
	 * @return
	 */
	public String falseDelete() {
		familySubjectInfo = new FamilySubjectInfo();
		familySubjectInfo.setSubjectId(subjectId);
		familySubjectInfo.setIsDelete(Constants.DELETED);
		try {
			familySubjectService
					.update(familySubjectInfo, getCurrentOperator());
			redirectionUrl = "family_subject!list.htm";
			return SUCCESS;
		} catch (Exception e) {
			log.error("删除信息异常", e);
			addActionError("删除信息异常" + e);
			return this.list();
		}
	}

	public Pagination<?> getPage() {
		return page;
	}

	public void setPage(Pagination<?> page) {
		this.page = page;
	}

	public FamilySubjectInfo getFamilySubjectInfo() {
		return familySubjectInfo;
	}

	public void setFamilySubjectInfo(FamilySubjectInfo familySubjectInfo) {
		this.familySubjectInfo = familySubjectInfo;
	}

	public FamilySubjectInfo getFamilySubjectInfoQuery() {
		return familySubjectInfoQuery;
	}

	public void setFamilySubjectInfoQuery(
			FamilySubjectInfo familySubjectInfoQuery) {
		this.familySubjectInfoQuery = familySubjectInfoQuery;
	}

	public String getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(String subjectId) {
		this.subjectId = subjectId;
	}

}
